//
//  INoteRecorder.h
//  INoteRecorder
//  音符录制
//  Created by 张宇飞 on 2020/9/23.
//  Copyright © 2020 元悦科技. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MIKMIDI/MIKMIDICommand.h>

NS_ASSUME_NONNULL_BEGIN

@interface INote : NSObject

@property(nonatomic, assign) NSTimeInterval onset;
@property(nonatomic, assign) NSUInteger pitch;
@property(nonatomic, assign) NSUInteger velocity;
@property(nonatomic, assign) UInt8 channel;

@end

typedef void (^INoteRecorderEventHandler)(NSTimeInterval packTime,
                                          NSArray<INote*>* _Nullable notes);

extern const NSTimeInterval kINoteRecorderMinPackInterval;

typedef NS_ENUM(NSInteger, INoteRecorderState) {
    kINoteRecorderState_Stopped,
    kINoteRecorderState_Recording,
    kINoteRecorderState_Pausing
};

@interface INoteRecorder : NSObject

// 默认为 kINoteRecorderState_Stopped（写该属性是线程安全的）
@property(nonatomic, readwrite) INoteRecorderState state;

// 是否记录 note off 事件。默认为 YES
@property(nonatomic, readwrite) BOOL isRecordNoteOff;

- (id)initWithHandler:(NSTimeInterval)packInterval
         eventHandler:(nonnull INoteRecorderEventHandler)eventHandler;

/**
 * 处理midi command 数据，过滤出来 note on/off 事件，打包并分发结果（该接口线程安全）
 */
- (void)process:(nonnull NSArray<MIKMIDICommand*>*)commands;

@end

NS_ASSUME_NONNULL_END
